package com.example.xd.tuiliu_test.videoplayer.widget.status;



import com.example.xd.tuiliu_test.videoplayer.PlayerManager;
import com.example.xd.tuiliu_test.videoplayer.util.AnimUtil;
import com.example.xd.tuiliu_test.videoplayer.widget.BasePlayerView;
import com.example.xd.tuiliu_test.videoplayer.widget.ControllerView;

import tv.danmaku.ijk.media.player.IMediaPlayer;


import static android.view.View.VISIBLE;

public abstract class BaseStatus {
    public int netStatus;
    ControllerView view;

    public BaseStatus(BasePlayerView view) {
        this.view = (ControllerView) view;
    }

    abstract public void play();

    abstract public void error();

    abstract public void completed();

    abstract public void onInfo(IMediaPlayer iMediaPlayer, int what, int i1);

    abstract public void netChange();
    //退到后台
    abstract public void onBack();
    //回到后台
    abstract public void onStart();

    public void onPrepared(IMediaPlayer iMediaPlayer) {

    }

    public void pause() {

    }

    /**
     *  当一个status开始时会调用
     */
    public void onStartStatus() {

    }

    /**
     *  当一个status结束时会调用
     */
    public void onStopStatus() {

    }

    public void restoreFromPlayerView() {

    }

    public void onStartScrolled() {

    }

    public void onEndScrolled() {

    }

    public void releasePlayer() {
        view.setStatus(view.waitinit);
        view.closeController(false);
        view.handler.removeMessages(view.CLOSE_CONTROLLER);
        AnimUtil.release(view);
        view.iv_screen_play.setVisibility(VISIBLE);
        view.iv_video_pic.setVisibility(VISIBLE);
        if (PlayerManager.getInstance().getPlayingView() == view) {
            PlayerManager.getInstance().setPlayingView(null);
        }
        view.release = true;
        if (view.player != null) {
            view.player.release();
            view.player = null;
        }
        if (view.surfaceTexture != null) {
            view.surfaceTexture.release();
            view.surfaceTexture = null;
        }
        if (view.textureView != null) {
            view.removeView(view.textureView);
            view.textureView = null;
        }
    }

    public void onItemRollOut() {

    }

    public abstract void copyStatusToChild(BasePlayerView view);
}
